<?php

/*
	Class: Mail_Plugin

	About: Author
		Jaybill McCarthy

	About: License
		<http://communit.as/docs/license>
*/
class Mail_Plugin {

	/* Group: Constructors */

	/*
		Function: Mail_Plugin
	*/
	function Mail_Plugin() {
		$this->_logger = Zend_Registry::get("logger");
	}

	/* Group: Instance Methods */

	/*
		Function: install
			Runs the database script to set up the tables needed for the Mail module.
	*/
	function install($params) {
		$script = new Cts_Db_Script("mail", "install");
		if (!$script) {
			$params['errors'] = $script->errors;
		}
		return $params;
	}

	/*
		Function: uninstall
			Drops the database tables that were used only for the Mail module.
	*/
	function uninstall($params) {
		$script = new Cts_Db_Script("mail", "uninstall");
		if (!$script) {
			$params['errors'] = $script->errors;
		}
		return $params;
	}

	/*
		Function: enable
			Not currently used.
	*/
	function enable($params) {
		return $params;
	}

	/*
		Function: disable
			Not currently used.
	*/
	function disable($params) {
		return $params;
	}
	
	function userDelete($params){
		//dd($params);
		$mail_table = new MailMessages();
		// delete this user's sent mail
		$where = $mail_table->getAdapter()->quoteInto('from_username = ? and folder = "SENT" ', $params['username']);
		$this->_logger->report('Deleting mail.',$where,Zend_Log::DEBUG);
		$mail_table->delete($where);
		
		// delete this user's incoming mail
		$where = $mail_table->getAdapter()->quoteInto('to_username = ? and folder = "INBOX"', $params['username']);
		$this->_logger->report('Deleting mail.',$where,Zend_Log::DEBUG);
		$mail_table->delete($where);
		
		return $params;
	}

}
